package com.example.myapplication.ui.information;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.myapplication.CardBag;
import com.example.myapplication.LoginActivity;
import com.example.myapplication.PayMent;
import com.example.myapplication.R;
import com.example.myapplication.SettingActivity;
import com.example.myapplication.Wode;
import com.example.myapplication.XiangCe;


public class informationFragment extends Fragment {
    private LinearLayout wode, setting, pay_ment, cardbag, xiangce, lv_sign_out;
    private ImageView userimg;
    private TextView username, tv_nicheng;
    View v;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        v = inflater.inflate(R.layout.fragment_information, container, false);
        initView(v);
        setListener();
        return v;

    }

    private void setListener() {
//        跳转到个人信息界面
        wode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), Wode.class);
                startActivity(intent);
            }
        });
//跳转到设置界面
        setting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1 = new Intent(getContext(), SettingActivity.class);
                startActivity(intent1);
            }
        });
//跳转到支付页面

        pay_ment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent2 = new Intent(getContext(), PayMent.class);
                startActivity(intent2);

            }
        });
//跳转到卡包页面
        cardbag.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent3 = new Intent(getContext(), CardBag.class);
                startActivity(intent3);
            }
        });
//跳转到相册
        xiangce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent4 = new Intent(getContext(), XiangCe.class);
                startActivity(intent4);
            }
        });

//        退出登录 跳转到login页面

        lv_sign_out.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent5 = new Intent(getContext(), LoginActivity.class);
                startActivity(intent5);
                showToast("你已退出登录！");

            }
        });

    }

    //    退出登录的提醒
    private void showToast(String s) {
        Toast.makeText(getContext(), s, Toast.LENGTH_LONG).show();
    }

    private void initView(View v) {
        wode = v.findViewById(R.id.wode);
        setting = v.findViewById(R.id.setting);
        pay_ment = v.findViewById(R.id.pay_ment);
        cardbag = v.findViewById(R.id.cardbag);
        xiangce = v.findViewById(R.id.xaingce);
        lv_sign_out = v.findViewById(R.id.lv_sign_out);


        userimg = v.findViewById(R.id.userimg);
//        同步用户名
        username = v.findViewById(R.id.username);
        //        同步修改昵称
        tv_nicheng = v.findViewById(R.id.tv_nicheng);
        //        同步朋友圈头像
        SharedPreferences sp = getActivity().getSharedPreferences("userinfo", Context.MODE_PRIVATE);
        //        同步头像
        userimg.setImageResource(sp.getInt("myimg", -1));
        //用户名
        username.setText(sp.getString("myname", ""));
        // 昵称
        tv_nicheng.setText(sp.getString("mynickname",""));
    }

    @Override
//    onstart 方法  更新数据
    public void onStart() {
        super.onStart();
        initView(v);
    }

}